package com.hr.fer.nmbp.lab2.test;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.hr.fer.nmbp.lab2.domain.Room;
import com.hr.fer.nmbp.lab2.persistence.RoomMapper;

public class Main {

private static SqlSession session = null;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
            System.out.println("Program started");
            String aResource = "myBatisConfig.xml";
            Reader reader = Resources.getResourceAsReader(aResource);
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
            System.out.println(sessionFactory.getConfiguration().getEnvironment().getDataSource().toString());
            session = sessionFactory.openSession();
            /*GuestMapper mapper = session.getMapper(GuestMapper.class);
            NumberOfGuests nog = new NumberOfGuests();
            mapper.callGetTotalGuest(nog);*/
            
            //ReservationMapper rm = session.getMapper(ReservationMapper.class);
            //rm.selectEmptyRooms(new TimeSpan(new Date(75,4,13), new Date(75,4,16)));
            
            //Reservation res = new Reservation(new Date(50), new Date(50), new Guest("123456","Kresimir","Misura"),
            //		new Room(5,2));
            //rm.delete(res);
            RoomMapper roomMapper = session.getMapper(RoomMapper.class);
            Room r1 = new Room();
            r1.setRoomNum(5);
            r1.setSize(2);
            roomMapper.deleteByPrimaryKey(5);
//            roomMapper.insertRoom(new Room(1, 4, true));
//            roomMapper.insertRoom(new Room(2, 2, false));
//            List<Room> rooms = roomMapper.selectAll();
//            Room room = roomMapper.getRoomByNumber(1);
//            System.out.println(room.isView());
         
            session.commit();
        } catch (Exception e) {
            System.err.println("Exception caught: " + e.getMessage());
        } finally {
            if (session != null) {
                session.close();
            }
        }
	}


}

